<?php

use yii\helpers\Html;
use yii\grid\GridView;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\SetMealOrderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '订单列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="set-meal-order-index col-sm-12" style="margin-top: 15px;">
    <div class="ibox ibox-content">
        <?php echo $this->render('_search', ['model' => $searchModel]); ?>


        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            'tableOptions' => ['class' => 'table table-striped'],
//            'options' => ['class' => 'grid-view', 'style' => 'overflow:auto', 'id' => 'grid'],
            //'filterModel' => $searchModel,
            'columns' => [
                    ['class'=>'yii\grid\SerialColumn','header' => '序号'],
                'alipay',
                'name',
                'mobile',
                'maketime',

                'product_name',
//                    'member.username',
                'address',
                [
                    'attribute' => 'status',
                    'value' => function ($m) {
                        return \common\models\Order::$status[$m->status];
                    }
                ],

                [
                    'attribute' => 'created_at',
                    'value' => function ($m) {
                        return date('Y-m-d', $m->created_at);
                    }
                ],
                [
                    'class' => 'yii\grid\ActionColumn',
                    'header' => '操作',
                    'headerOptions' => ['width' => '150px'],
                    'template' => '{view} {status} {delete} {is-cancel}',
                    'buttons' => [
                        'view' => function($url, $model, $key){
                            return Html::a('订单详情', $url,['class' =>'btn btn-outline btn-default btn-xs', 'style' => "margin-top:10px"]);
                        },
                        'status' => function ($url, $model, $key) {
                            if($model->status == \common\models\Order::STATUS_START) {
                                return Html::a('上门取件', $url.'&status=10', ['data-confirm' => '你确定要取件吗?', 'class' => 'btn btn-outline btn-info btn-xs', 'style' => "margin-top:10px"]);
                            }elseif ($model->status==\common\models\Order::STATUS_INIT){
                                return Html::a('签收', $url.'&status=20', ['data-confirm' => '你确定要验机吗?', 'class' => 'btn btn-outline btn-info btn-xs', 'style' => "margin-top:10px"]);
                            }elseif ($model->status==\common\models\Order::STATUS_EXAMINE){
                                return Html::a('专业验机', $url.'&status=30', ['data-confirm' => '你确定要验机吗?', 'class' => 'btn btn-outline btn-info btn-xs', 'style' => "margin-top:10px"]);
                            }elseif ($model->status==\common\models\Order::STATUS_FAIL){
                                return Html::a('成交放款', $url.'&status=40', ['data-confirm' => '你确定要放款吗?', 'class' => 'btn btn-outline btn-info btn-xs', 'style' => "margin-top:10px"]);
                            }
                        },
                        'is-cancel' => function ($url, $model, $key) {
                            if($model->is_cancel==\common\models\Order::IS_NO){
                                return Html::a('取消订单', $url, ['data-confirm' => '你确定要取消吗?', 'data-method' => 'POST', 'class' => 'btn btn-outline btn-danger btn-xs', 'style' => "margin-top:10px"]);
                            }
                        },
                        'delete' => function ($url, $model, $key) {
                            return Html::a('删除', $url, ['data-confirm' => '你确定要删除吗?', 'data-method' => 'POST', 'class' => 'btn btn-outline btn-danger btn-xs', 'style' => "margin-top:10px"]);
                        }
                    ],
                ],
            ],
        ]); ?>
    </div>
</div>
